#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 105;

int n, m;
char g[N][N];

void dfs(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m) return;
  if (g[x][y] != 'W') return;
  g[x][y] = '.';
  rep(dx, -1, 1) rep(dy, -1, 1) {
    int xx = x + dx, yy = y + dy;
    dfs(xx, yy);
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) rep(j, 1, m) cin >> g[i][j];
  int cnt = 0;
  rep(i, 1, n) rep(j, 1, m) {
    if (g[i][j] == 'W') {
      dfs(i, j);
      cnt++;
    }
  }
  cout << cnt;
  return 0;
}